package crazymakercircle;

import lombok.extern.slf4j.Slf4j;

import java.nio.Buffer;
import java.nio.IntBuffer;

/**
 * @Author: DRevelation
 * @Date: 2021/10/9 13:58
 */
@Slf4j
public class UserBuffer {

    static IntBuffer buffer = null;

    static void allocateTest() {
        buffer = IntBuffer.allocate(20);
        log.info("===========after allocate============");
    }

    static void putData() {
        for (int i = 0; i < 5; i++) {
            buffer.put(i);
        }
        log.info("==========put data=============");
    }

    static void printInfo() {
        log.info("capacity=" + buffer.capacity());
        log.info("position=" + buffer.position());
        log.info("limit=" + buffer.limit());
    }

    public static void main(String[] args) {
        allocateTest();
        printInfo();
        putData();
        printInfo();
        buffer.flip();
        log.info("=============flip=============");
        printInfo();
    }
}
